package com.wangp.enjoywork.service;

import java.io.File;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

@Service
public class DeleteFileService {
	
	Logger logger = LoggerFactory.getLogger(getClass());
	
	@Async
	public void deleteFile(String filePath){
		logger.info("路径为：{}的文件将在15分钟后删除",filePath);
		//开启异步任务，文件生成后，15分钟内会自动删除
		try {
			Thread.sleep(1000*60*15);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		File file = new File(filePath);
		if(file.exists()){
			file.delete();
			logger.info("路径为：{}的文件将被删除",filePath);
		}
	}
	
}
